//
// Created by hentai on 24-12-9.
//

#include "cl/hentai_book.h"

#include <stdio.h>
#include <stdlib.h>

void book_struct() {

    struct Book * books = (struct Book *) malloc(3 * sizeof(struct Book));
    for (int i = 0; i < 3; i++) {
        (books + i)->number = i + 1;
        (books + i)->title = (char *) malloc(20 * sizeof(char));
        snprintf((books + i)->title, 20, "哈利·波特%d", i + 1);
        (books + i)->price = 250 * (i + 1);
    }

    for (int i = 0; i < 3; i++) {
        const double all_price = compute_book_price(books + i);
        printf("%s 总价格 %lf\n", (books + i)->title, all_price);
    }

    free(books);
}

double compute_book_price(const struct Book *book) {
    const double sum = book->price * book->number;
    return sum;
}

void free_book(const struct Book *book) {
    free(book->title);
}

